/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License"),
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @addtogroup netstack
 * @{
 *
 * @brief Provides C APIs for the Http client module.
 *
 * @since 20
 */

/**
 * @file net_http_type.h
 * @brief Defines the data structure for the C APIs of the http module.
 *
 * @library libnet_http.so
 * @kit NetworkKit
 * @syscap SystemCapability.Communication.NetStack
 * @since 20
 */

#ifndef NET_HTTP_TYPE_H
#define NET_HTTP_TYPE_H

#ifdef __cplusplus
extern "C" {
#endif

#define OHOS_HTTP_MAX_PATH_LEN 128
#define OHOS_HTTP_MAX_STR_LEN 256
#define OHOS_HTTP_DNS_SERVER_NUM_MAX 3

/**
 * @brief Defines http error code.
 *
 * @since 20
 */
typedef enum Http_ErrCode {
  /** Operation success. */
  OH_HTTP_RESULT_OK = 0,
  /** @brief Parameter error. */
  OH_HTTP_PARAMETER_ERROR = 401,
  /** @brief Permission denied. */
  OH_HTTP_PERMISSION_DENIED = 201,
  /** @brief Error code base. */
  OH_HTTP_NETSTACK_E_BASE = 2300000,
  /** @brief Unsupported protocol. */
  OH_HTTP_UNSUPPORTED_PROTOCOL = (OH_HTTP_NETSTACK_E_BASE + 1),
  /** @brief Invalid URL format or missing URL. */
  OH_HTTP_INVALID_URL = (OH_HTTP_NETSTACK_E_BASE + 3),
  /** @brief Failed to resolve the proxy name. */
  OH_HTTP_RESOLVE_PROXY_FAILED = (OH_HTTP_NETSTACK_E_BASE + 5),
  /** @brief Failed to resolve the host name. */
  OH_HTTP_RESOLVE_HOST_FAILED = (OH_HTTP_NETSTACK_E_BASE + 6),
  /** @brief Failed to connect to the server. */
  OH_HTTP_CONNECT_SERVER_FAILED = (OH_HTTP_NETSTACK_E_BASE + 7),
  /** @brief Invalid server response. */
  OH_HTTP_INVALID_SERVER_RESPONSE = (OH_HTTP_NETSTACK_E_BASE + 8),
  /** @brief Access to the remote resource denied. */
  OH_HTTP_ACCESS_REMOTE_DENIED = (OH_HTTP_NETSTACK_E_BASE + 9),
  /** @brief Error in the HTTP2 framing layer. */
  OH_HTTP_HTTP2_FRAMING_ERROR = (OH_HTTP_NETSTACK_E_BASE + 16),
  /** @brief Transferred a partial file. */
  OH_HTTP_TRANSFER_PARTIAL_FILE = (OH_HTTP_NETSTACK_E_BASE + 18),
  /** @brief Failed to write the received data to the disk or application. */
  OH_HTTP_WRITE_DATA_FAILED = (OH_HTTP_NETSTACK_E_BASE + 23),
  /** @brief Upload failed. */
  OH_HTTP_UPLOAD_FAILED = (OH_HTTP_NETSTACK_E_BASE + 25),
  /** @brief Failed to open or read local data from the file or application. */
  OH_HTTP_OPEN_LOCAL_DATA_FAILED = (OH_HTTP_NETSTACK_E_BASE + 26),
  /** @brief Out of memory. */
  OH_HTTP_OUT_OF_MEMORY = (OH_HTTP_NETSTACK_E_BASE + 27,
  /** @brief Operation timeout. */
  OH_HTTP_OPERATION_TIMEOUT = (OH_HTTP_NETSTACK_E_BASE + 28),
  /** @brief The number of redirections reaches the maximum allowed. */
  OH_HTTP_TOO_MANY_REDIRECTIONS = (OH_HTTP_NETSTACK_E_BASE + 47),
  /** @brief The server returned nothing (no header or data). */
  OH_HTTP_SERVER_RETURNED_NOTHING = (OH_HTTP_NETSTACK_E_BASE + 52),
  /** @brief Failed to send data to the peer. */
  OH_HTTP_SEND_DATA_FAILED = (OH_HTTP_NETSTACK_E_BASE + 55),
  /** @brief Failed to receive data from the peer. */
  OH_HTTP_RECEIVE_DATA_FAILED = (OH_HTTP_NETSTACK_E_BASE + 56),
  /** @brief Local SSL certificate error. */
  OH_HTTP_SSL_CERTIFICATE_ERROR = (OH_HTTP_NETSTACK_E_BASE + 58),
  /** @brief The specified SSL cipher cannot be used. */
  OH_HTTP_SSL_CIPHER_USED_ERROR = (OH_HTTP_NETSTACK_E_BASE + 59),
  /** @brief Invalid SSL peer certificate or SSH remote key. */
  OH_HTTP_INVALID_SSL_PEER_CERT = (OH_HTTP_NETSTACK_E_BASE + 60),
  /** @brief Invalid HTTP encoding format. */
  OH_HTTP_INVALID_ENCODING_FORMAT = (OH_HTTP_NETSTACK_E_BASE + 61),
  /** @brief Maximum file size exceeded. */
  OH_HTTP_FILE_TOO_LARGE = (OH_HTTP_NETSTACK_E_BASE + 63),
  /** @brief Remote disk full. */
  OH_HTTP_REMOTE_DISK_FULL = (OH_HTTP_NETSTACK_E_BASE + 70),
  /** @brief Remote file already exists. */
  OH_HTTP_REMOTE_FILE_EXISTS = (OH_HTTP_NETSTACK_E_BASE + 73),
  /** @brief The SSL CA certificate does not exist or is inaccessible. */
  OH_HTTP_SSL_CA_NOT_EXIST = (OH_HTTP_NETSTACK_E_BASE + 77),
  /** @brief Remote file not found. */
  OH_HTTP_REMOTE_FILE_NOT_FOUND = (OH_HTTP_NETSTACK_E_BASE + 78),
  /** @brief Authentication error. */
  OH_HTTP_AUTHENTICATION_ERROR = (OH_HTTP_NETSTACK_E_BASE + 94),
  /** @brief It is not allowed to access this domain. */
  OH_HTTP_ACCESS_DOMAIN_NOT_ALLOWED = (OH_HTTP_NETSTACK_E_BASE + 998),
  /** @brief Unknown error. */
  OH_HTTP_UNKNOWN_ERROR = (OH_HTTP_NETSTACK_E_BASE + 999)
} Http_ErrCode;

/**
 * @brief Defines http response code.
 *
 * @since 20
 */
typedef enum Http_ResponseCode {
    /** Request succeeded. */
    HTTP_SUCCESS = 200,
    /** The request has been accepted for processing, but the processing has not been completed. */
    HTTP_ACCEPTED = 202,
    /** The server successfully processed the request and is not returning any content. */
    HTTP_NO_CONTENT = 204,
    /** The server successfully processed the request, but is not returning any content and requires the requester to reset the document view. */
    HTTP_RESET_CONTENT = 205,
    /** The server successfully processed the request and is returning content for the user to download. */
    HTTP_PARTIAL_CONTENT = 206,
    /** The requested resource has been assigned a new permanent URL. */
    HTTP_MOVED_PERMANENTLY = 301,
    /** The requested resource is temporarily located under a different URL. */
    HTTP_FOUND = 302,
    /** The client should continue the request using the specified proxy. */
    HTTP_USE_PROXY = 305,
    /** The server is redirecting the client to a different resource, as indicated by the URL in the Location header field. */
    HTTP_TEMPORARY_REDIRECT = 307,
    /** The server is redirecting the client to a different resource permanently, as indicated by the URL in the Location header field. */
    HTTP_PERMANENT_REDIRECT = 308,
    /** The request is missing required authentication credentials. */
    HTTP_UNAUTHORIZED = 401,
    /** The server understood the request but refuses to authorize it. */
    HTTP_FORBIDDEN = 403,
    /** The requested resource could not be found. */
    HTTP_NOT_FOUND = 404,
    /** The request method is not supported by the server for the requested resource. */
    HTTP_METHOD_NOT_ALLOWED = 405,
    /** The server cannot produce a response matching the list of acceptable values defined in the request's proactive content negotiation headers. */
    HTTP_NOT_ACCEPTABLE = 406,
    /** The client must first authenticate itself with the proxy. */
    HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
    /** The request could not be completed due to a conflict with the current state of the target resource. */
    HTTP_CONFLICT = 409,
    /** The requested resource is no longer available at the server and no forwarding address is known. */
    HTTP_GONE = 410,
    /** The server refuses to process the request because the request payload is larger than the server is willing or able to process. */
    HTTP_PAYLOAD_TOO_LARGE = 413,
    /** The server cannot meet the requirements of the Expect request-header field. */
    HTTP_EXPECTATION_FAILED = 417,
    /** The request was directed at a server that is not able to produce a response. */
    HTTP_MISDIRECTED_REQUEST = 421,
    /** The server is unwilling to process the request because its header fields are too large. */
    HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
    /** The server encountered an unexpected condition that prevented it from fulfilling the request. */
    HTTP_INTERNAL_SERVER_ERROR = 500,
    /** The server does not support the functionality required to fulfill the request. */
    HTTP_NOT_IMPLEMENTED = 501,
    /** The server, while acting as a gateway or proxy, received an invalid response from the upstream server. */
    HTTP_BAD_GATEWAY = 502,
    /** The server is currently unavailable (because it is overloaded or down for maintenance). */
    HTTP_SERVICE_UNAVAILABLE = 503,
    /** The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server. */
    HTTP_GATEWAY_TIMEOUT = 504,
    /** The server does not support the HTTP protocol version used in the request. */
    HTTP_HTTP_VERSION_NOT_SUPPORTED = 505
} Http_ResponseCode;

#ifdef __cplusplus
}
#endif

#endif // NET_HTTP_TYPE_H